home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Programmer Disk
/
The Programmer Disk (Microforum).iso
/
xpro
/
pascal
/
pro23
/
bas2pas.pas
next >
Wrap
Pascal/Delphi Source File
|
1987-05-28
|
4KB
|
103 lines
PROGRAM BAS2PAS;
{ Test program to read single precision real numbers from a BASIC }
{ random access file into Turbo Pascal. }
{ D Adams July 1984 }
{ Fairfield CA }
CONST
MAXREC = 12;
TYPE
PNUM = ARRAY[1..6] OF CHAR; { Pascal real number a characters }
BNUM = ARRAY[1..4] OF CHAR; { BASIC real number as characters }
DBASE = RECORD
N1 : BNUM;
N2 : BNUM;
END;
VAR
PARMFILE : FILE OF DBASE;
PARMREC : DBASE;
BN1,BN2 : REAL;
PNR : INTEGER;
PROCEDURE CVS(VAR PRL:REAL; BRL: BNUM );
{ Procedure to convert BASIC 4 byte real to Turbo Pascal 6 byte real }
VAR
TMP : REAL; { Temperary Pascal Real }
C1,C2,C3,C4 : CHAR;
C : PNUM ABSOLUTE TMP; { String array with same address }
BEGIN
{ Copy four bytes from file buffer. }
C1:= COPY(BRL,1,1);
C2:= COPY(BRL,2,1);
C3:= COPY(BRL,3,1);
C4:= COPY(BRL,4,1);
{ Change position of exponent byte and zero extra 2 bytes. }
FILLCHAR(C[1],1,C4);
FILLCHAR(C[2],1,CHR(0));
FILLCHAR(C[3],1,CHR(0));
FILLCHAR(C[4],1,C1);
FILLCHAR(C[5],1,C2);
FILLCHAR(C[6],1,C3);
{ Place value into passed parameter. }
PRL:= TMP;
END;
BEGIN
CLRSCR;
ASSIGN(PARMFILE,'BASFILE.DAR'); RESET(PARMFILE);
WRITE('RECORD NUMBER: ');READLN(PNR);
{ Continue until record number outside range 1..MAXREC is chosen. }
WHILE PNR IN [1..MAXREC] DO
BEGIN
SEEK(PARMFILE,PNR-1);
READ(PARMFILE,PARMREC);
WITH PARMREC DO
BEGIN
{ Call conversions }
CVS(BN1,N1);
CVS(BN2,N2);
WRITELN(BN1:8:2,BN2:8:2);
END;
WRITE('RECORD NUMBER: '); READLN(PNR);
END;
CLOSE(PARMFILE);
END.
{ The above program will read a sample random access file }
{ written by the basic program listed below. This file }
{ contains two single presision real numbers (4 bytes each). }
{ Each real is read in as a 4 character array and converted }
{ into a six byte Turbo Pascal real number. The procedure }
{ above should allow a Turbo Pascal program to read any }
{ single precision real number from a BASIC random access }
{ file. }
{ }
{ BASIC Program: }
{ }
{ 10 OPEN"R",1,"BASFILE.DAR",8 }
{ 20 FIELD 1, 4 AS N1$, 4 AS N2$ }
{ 30 FOR I=1 TO 12 }
{ 40 LSET N1$= MKS$(1.1*I) }
{ 50 LSET N2$= MKS$(100 + 1.1*I) }
{ 60 PUT 1,I }
{ 70 NEXT I }
{ 80 CLOSE }
{ }
{ Note: For conversion of Turbo Pascal Reals to BASIC see }
{ PAS2BAS.BAS }